We will use Cytoscape to create an enrichment map (EM) of our GSEA results. The enrichment map will allow us to visualize the relationships between the gene sets that were significantly enriched in our analysis.
Enrichment Map Setup
Prior to creating our EM, we will setup the thresholds (Table 6.1) for our analysis. The thresholds will allow us to filter out gene sets that aren’t as significant as we need for analysis.
Table 6.1: Thresholds used for the Enrichment Map analysis.
| 1 |
0.05 |
0.375 |
The p-value threshold will ensure that only gene sets with a p-value of at most 1.0 will be included in the analysis. In a similar fashion, the q-value threshold is used to limit the gene sets in our analysis to those with \(q-value < 0.05\). The similarity threshold is used to filter out gene sets that are not similar enough to be connected in the enrichment map. The similarity metric used is Combined.
With the thresholds and input data set, we can now proceed with creating our EM.
Using Cytoscape
Our network analysis will be ran using Cytoscape and apps that are available through it9. As a result, we must first ensure Cytoscape is running and that we can connect to it through its REST API (CyREST)10.
## Cytoscape API Version: v1
## Cytoscape Version Info: 3.10.2
The EM is created through the enrichmentmap app available through the Cytoscape App Store. Since it runs through Cytoscape, we must first ensure that Cytoscape is running and that we can connect to it through the REST API (CyREST). Overall, our Cytoscape setup will involve the following steps:
- Ensure
EnrichmentMap, AutoAnnotate, and any other necessary apps are installed in Cytoscape.
- Upload the required files to Cytoscape.
- Create the enrichment map.
- Export an image of the enrichment map.
Installing Cytoscape Apps
We use the installApp function provided by RCy3 to install EnrichmentMap and AutoAnnotate.
# Wrapper function to install Cytoscape apps using RCy3
#
# Args:
# cyrest_url: The base URL of the Cytoscape REST API
# apps: A list of apps to install
#
# Returns:
# A list of the newly installed apps
install_cytoscape_apps <- function(cyrest_url, apps) {
# Load a list of the currently installed apps
installed_apps <- RCy3::getInstalledApps(base.url = cyrest_url)
new_apps <- c()
for (app in apps) {
# Check if the app is already installed
if (!any(grepl(tolower(app), tolower(installed_apps)))) {
RCy3::installApp(app, base.url = cyrest_url)
new_apps <- c(new_apps, app)
} else {
message(sprintf("App '%s' is already installed.", app))
}
}
return(new_apps)
}
Table: (#tab:install-cytoscape-apps)Newly installed Cytoscape apps.
Uploading Data to Cytoscape
To perform our analysis, we need to provide the following files to Cytoscape:
- The gene set file in
.gmt format.
- The enrichment results file.
- The expression data file.
- The ranks file.
Since Cytoscape is running on the host operating system, we have to provide it with the input files that were generated in the Docker container. We will use the CyREST API to upload these files to Cytoscape.
# Function to upload data to Cytoscape using the provided cyrest_url
#
# Args:
# cyrest_url: The base URL of the Cytoscape REST API
# files: A list of files to upload
#
# Returns:
# A logical value indicating whether the upload was successful or not
upload_data_to_cytoscape <- function(cyrest_url, files) {
# Store the uploaded file paths
uploaded_paths <- c()
for (file in files) {
# Build the POST request
bname <- basename(file)
r <- httr::POST(
url = paste0(
cyrest_url, "/enrichmentmap/textfileupload?fileName=", bname
),
config = list(),
body = list(file = httr::upload_file(file)),
encode = "multipart",
handle = NULL
)
# Check if the upload was successful
uploaded_paths <- c(uploaded_paths, httr::content(r, "parsed")$path)
}
return(uploaded_paths)
}
Create the Enrichment Map
With the Cytoscape Apps installed and the data imported, we can now move on to creating our EMs. We will create two EMs: one with a q-value threshold of 0.05 (not shown) and another with a q-value threshold of 0.01 (Figure 6.1). Both EMs will use a p-value threshold of 1.0.
# Function to create an enrichment map using the provided cyrest_url
#
# Args:
# cur_model_name: The name of the current model
# pvalue_gsea_threshold: The p-value threshold for the GSEA analysis
# qvalue_gsea_threshold: The q-value threshold for the GSEA analysis
# similarity_threshold: The similarity threshold for the enrichment map
# similarity_metric: The similarity metric for the enrichment map
# gsea_ranks_file: The file containing the GSEA ranks
# gsea_results_filename: The file containing the GSEA results
# expression_file_fullpath: The full path to the expression data file
# gmt_gsea_file: The file containing the GSEA gene sets
# current_base: The base URL of the Cytoscape REST API
#
# Returns:
# The response from the Cytoscape REST API
create_enrichment_map <- function(
cur_model_name, pvalue_gsea_threshold, qvalue_gsea_threshold,
similarity_threshold, similarity_metric, gsea_ranks_file,
gsea_results_filename, expression_file_fullpath, gmt_gsea_file,
current_base
) {
# Construct the network name
current_network_name <- paste(
cur_model_name,
pvalue_gsea_threshold,
qvalue_gsea_threshold,
sep = "_"
)
# Construct the EM command
em_command <- paste(
'enrichmentmap build analysisType="gsea"',
"gmtFile=", gmt_gsea_file,
"pvalue=", pvalue_gsea_threshold,
"qvalue=", qvalue_gsea_threshold,
"similaritycutoff=", similarity_threshold,
"coefficients=", similarity_metric,
"ranksDataset1=", gsea_ranks_file,
"enrichmentsDataset1=", gsea_results_filename,
"filterByExpressions=false",
"expressionDataset1=", expression_file_fullpath,
"gmtFile=", gmt_gsea_file,
sep = " "
)
# Execute the EM command
response <- RCy3::commandsGET(em_command, base.url = current_base)
# Initialize network SUID
current_network_suid <- 0
# Check if the command execution failed
if (grepl(pattern = "Failed", response)) {
return(paste(response))
} else {
current_network_suid <- response
}
# Check if the network name is unique
current_names <- RCy3::getNetworkList(base.url = current_base)
# If the name already exists, prepend the SUID to the name
if (current_network_name %in% current_names) {
current_network_name <- paste(
current_network_suid,
current_network_name,
sep = "_"
)
}
# Rename the network
response <- RCy3::renameNetwork(
title = current_network_name,
network = as.numeric(current_network_suid),
base.url = current_base
)
return(response)
}
# 1. Initial EM (p = 1.0, q = 0.05)
em_response <- create_enrichment_map(
analysis_name, pvalue_gsea_threshold, qvalue_gsea_threshold,
similarity_threshold, similarity_metric, rank_file_host,
enrichment_results_host, expression_data_host, gmt_file_host,
cyrest_url
)
em_response_suid <- em_response$network
# 2. More Stringent EM (p = 1.0, q = 0.01)
analysis_name_stringent <- paste0(analysis_name, "_stringent")
em_response_stringent <- create_enrichment_map(
analysis_name, pvalue_gsea_threshold, 0.01,
similarity_threshold, similarity_metric, rank_file_host,
enrichment_results_host, expression_data_host, gmt_file_host,
cyrest_url
)
em_response_stringent_suid <- em_response_stringent$network
Unfortunately using Docker, we cannot directly access the images of the networks we create in Cytoscape. This is because of the fundamental separation of filesystems between Docker and the host system. The issues will differ based on the function of RCy3 used, but the reason behind said issues will be the same.
RCy3::exportImage will try to export the image in the current working directory (/home/rstudio/projects/Assignment_3), which is not accessible from the host system (and therefore Cytoscape).
RCy3::commandsPOST will try to save the image in the Cytoscape session directory, which is not accessible from this Docker container.